package dz.home.zk7;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.zkoss.zul.Button;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Comboitem;
import org.zkoss.zul.Window;

public class LoginWindow extends Window {

	private static final long serialVersionUID = 1L;
	private Button btn = null;
	
	public void onCreate() throws InterruptedException {
		this.setTitle(" Login");
		this.setClosable(false);
		this.setVisible(true);
		Combobox comboRole = (Combobox) this.getFellow("role");
		boolean first = false;
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			String serverName = "192.168.30.211";
			String user = "gcb";
			String password = "compiere";
			String SID = "compiere";
			String URL = "jdbc:oracle:thin:@" + serverName + ":" + 1521 + ":"
					+ SID;
			Connection conn = DriverManager.getConnection(URL, user, password);
			String SQL = "Select ad_role_id, name from ad_role where "
					+ "rownum <= 30 and name <> 'Admin_CU' order by name asc";
			Statement stat = conn.createStatement();
			stat.setMaxRows(10);
			ResultSet rs = stat.executeQuery(SQL);
		
		while (rs.next()) {
			Comboitem itemRole = new Comboitem();
			itemRole.setLabel(rs.getString(2));
			itemRole.setId(String.valueOf(rs.getString(1)));
			comboRole.appendChild(itemRole);
			if (!first) {
				comboRole.setValue(itemRole.getLabel());
				first = true;
			}
		}
	}
	catch (Exception e) {
		e.printStackTrace();
	} 
	}

	public void onCancel() throws InterruptedException {
		// cancel any changes
		this.onCreate();
	}

}